<?php

namespace app\member\model;

use think\helper\Hash;
use think\Db;

/**
 * 产品类别模型
 */
class Types extends \think\Model {
    use \app\common\traits\TreeArray,
        \app\common\traits\SortArray;

    protected $pk = 'id';
    protected $autoWriteTimestamp = true;

    public function getTypes($types = 'id,path,title', $type = 'sort',$key = 'id') {
            $list = Db::view('Types', $types)->order('orders,id')->select();

        if (!empty($list)) {
            switch ($type) {
                case 'tree':

                    return $this->buildTree($list);
                case 'sort':
                    return $this->resort($list, $key);
                default:
                    return $list;
            }
        } else {
            return[];
        }
    }

}
